<%@page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="f" uri="http://example.com/functions" %>
<%@ page import="com.sxp.dao.RoleEnum" %>

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="UTF-8">
    <title>Lunch Ordering System - Food Selection</title>
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/food_selection.css" rel="stylesheet">

    <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/food_selection.js"></script>
</head>
<body>
    <div class="container">
        <jsp:include page="menu.jsp">
        <jsp:param value="d" name="accessRole" />
        </jsp:include>
        <table class="table table-bordered table-condensed table-bordered">
            <tr>
                <th>Day</th><th>${f:getThisMonthName()} ${f:getThisMonthYear()}</th><th>${f:getNextMonthName()} ${f:getNextMonthYear()}</th><th>${f:getAfterNextMonthName()} ${f:getAfterNextMonthYear()}</th>
            </tr>
            <tr>
                <td>All</td>
                <td>
                    <select id="month1s" class="monthalls">
                        <c:forEach var="ricetype" items="${ricetypes}">
                            <option value="${ricetype.riceId}">${ricetype.riceType}</option>
                        </c:forEach>
                    </select>
                    <c:forEach var="mealtype" items="${mealtypes}">
                        <input id="month1${mealtype.mealId}" class="monthall" type="radio" name="month1all" value="${mealtype.mealId}">${mealtype.mealType}
                    </c:forEach>
                </td>
                <td>
                    <select id="month2s" class="monthalls">
                        <c:forEach var="ricetype" items="${ricetypes}">
                            <option value="${ricetype.riceId}">${ricetype.riceType}</option>
                        </c:forEach>
                    </select>
                    <c:forEach var="mealtype" items="${mealtypes}">
                        <input id="month2${mealtype.mealId}" class="monthall" type="radio" name="month2all" value="${mealtype.mealId}">${mealtype.mealType}
                    </c:forEach>
                </td>
                <td>
                    <select id="month3s" class="monthalls">
                        <c:forEach var="ricetype" items="${ricetypes}">
                            <option value="${ricetype.riceId}">${ricetype.riceType}</option>
                        </c:forEach>
                    </select>
                    <c:forEach var="mealtype" items="${mealtypes}">
                        <input id="month3${mealtype.mealId}" class="monthall" type="radio" name="month3all" value="${mealtype.mealId}">${mealtype.mealType}
                    </c:forEach>
                </td>
            </tr>
            <form action="UserController?action=saveFoodSelections" method="post">
            <tr>
            <td colspan="4">
            <input id="savebtn" type="submit" value="Save" class="btn btn-primary btn-xs">
            <input name="ndays1" type="hidden" value="${f:getThisMonthDays()}" >
            <input name="ndays2" type="hidden" value="${f:getNextMonthDays()}" >
            <input name="ndays3" type="hidden" value="${f:getAfterNextMonthDays()}" >
            </td>
            </tr>
            <c:forEach var="i" begin="1" end="31">
                <tr>
                    <td>${i}</td>
                    <td class="${f:getThisMonthDayClass(i)}">
                        <c:if test="${i <= f:getThisMonthDays()}">
                            <input name="date1${i}" type="hidden" value="${i}/${f:getThisMonth()}/${f:getThisMonthYear()}" >
                            <c:choose>
                                <c:when test="${(i <= foodselections1.size()) && (i == foodselections1.get(i-1).day)}">
                                    <select name="ricetype1${i}" class="${f:getThisMonthDayClass(i)} ${f:getHide(i)} month1ss">
                                         <c:forEach var="ricetype" items="${ricetypes}">
                                               <option value="${ricetype.riceId}" <c:if test="${foodselections1.get(i-1).riceId == ricetype.riceId}">selected</c:if>>${ricetype.riceType}</option>
                                         </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype1${i}" type="radio" value="${mealtype.mealId}" <c:if test="${foodselections1.get(i-1).mealId == mealtype.mealId}">checked</c:if> class="${f:getThisMonthDayClass(i)} ${f:getHide(i)} month1${mealtype.mealId}r"><font class="${f:getHide(i)}">${mealtype.mealType}</font>
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <select name="ricetype1${i}" class="${f:getThisMonthDayClass(i)} ${f:getHide(i)} month1ss">
                                        <c:forEach var="ricetype" items="${ricetypes}">
                                               <option value="${ricetype.riceId}" <c:if test="${ricetype.riceId == 0}">selected</c:if>>${ricetype.riceType}</option>
                                        </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype1${i}" type="radio" value="${mealtype.mealId}" <c:if test="${mealtype.mealId == 4}">checked</c:if> class="${f:getThisMonthDayClass(i)} ${f:getHide(i)} month1${mealtype.mealId}r"><font class="${f:getHide(i)}">${mealtype.mealType}</font>
                                    </c:forEach>
                                </c:otherwise>
                            </c:choose>
                        </c:if>
                    </td>
                    <td class="${f:getNextMonthDayClass(i)}">
                        <c:if test="${i <= f:getNextMonthDays()}">
                            <input name="date2${i}" type="hidden" value="${i}/${f:getNextMonth()}/${f:getNextMonthYear()}" >
                            <c:choose>
                                <c:when test="${(i <= foodselections2.size()) && (i == foodselections2.get(i-1).day)}">
                                    <select name="ricetype2${i}" class="${f:getNextMonthDayClass(i)} nonhide month2ss">
                                         <c:forEach var="ricetype" items="${ricetypes}">
                                               <option value="${ricetype.riceId}" <c:if test="${foodselections2.get(i-1).riceId == ricetype.riceId}">selected</c:if>>${ricetype.riceType}</option>
                                         </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype2${i}" type="radio" value="${mealtype.mealId}" <c:if test="${foodselections2.get(i-1).mealId == mealtype.mealId}">checked</c:if> class="${f:getNextMonthDayClass(i)} nonhide month2${mealtype.mealId}r">${mealtype.mealType}
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <select name="ricetype2${i}" class="${f:getNextMonthDayClass(i)} nonhide month2ss">
                                        <c:forEach var="ricetype" items="${ricetypes}">
                                               <option value="${ricetype.riceId}" <c:if test="${ricetype.riceId == 0}">selected</c:if>>${ricetype.riceType}</option>
                                        </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype2${i}" type="radio" value="${mealtype.mealId}" <c:if test="${mealtype.mealId == 4}">checked</c:if> class="${f:getNextMonthDayClass(i)} nonhide month2${mealtype.mealId}r">${mealtype.mealType}
                                    </c:forEach>
                                </c:otherwise>
                            </c:choose>
                        </c:if>
                    </td>
                    <td class="${f:getAfterNextMonthDayClass(i)}">
                        <c:if test="${i <= f:getAfterNextMonthDays()}">
                            <input name="date3${i}" type="hidden" value="${i}/${f:getAfterNextMonth()}/${f:getAfterNextMonthYear()}" >
                            <c:choose>
                                <c:when test="${(i <= foodselections3.size()) && (i == foodselections3.get(i-1).day)}">
                                    <select name="ricetype3${i}" class="${f:getAfterNextMonthDayClass(i)} nonhide month3ss">
                                        <c:forEach var="ricetype" items="${ricetypes}">
                                                <option value="${ricetype.riceId}" <c:if test="${foodselections3.get(i-1).riceId == ricetype.riceId}">selected</c:if>>${ricetype.riceType}</option>
                                        </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype3${i}" type="radio" value="${mealtype.mealId}" <c:if test="${foodselections3.get(i-1).mealId == mealtype.mealId}">checked</c:if> class="${f:getAfterNextMonthDayClass(i)} nonhide month3${mealtype.mealId}r">${mealtype.mealType}
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <select name="ricetype3${i}" class="${f:getAfterNextMonthDayClass(i)} nonhide month3ss">
                                        <c:forEach var="ricetype" items="${ricetypes}">
                                               <option value="${ricetype.riceId}" <c:if test="${ricetype.riceId == 0}">selected</c:if>>${ricetype.riceType}</option>
                                        </c:forEach>
                                    </select>
                                    <c:forEach var="mealtype" items="${mealtypes}">
                                        <input name="mealtype3${i}" type="radio" name="month3${i}" value="${mealtype.mealId}" <c:if test="${mealtype.mealId == 4}">checked</c:if> class="${f:getAfterNextMonthDayClass(i)} nonhide month3${mealtype.mealId}r">${mealtype.mealType}
                                    </c:forEach>
                                </c:otherwise>
                            </c:choose>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
            </form>
        </table>
	</div>
</body>
</html>